<template>
  <basic-container>
    <el-row :gutter="20">
      <!-- <el-col :span="6">
        <div class="dis-center">
          <span class="text-fs-14">项目名称：</span>
          <select-page
            ref="searchProjectSelect"
            label="projectName"
            value="projectCode"
            :select.sync="countSearch.projectCode"
            :url="'division/division_project/pageList'"
            placeholder-text="项目"
            filter-key="searchParam"
            width-fill
          ></select-page>
        </div>
      </el-col> -->
      <el-col :span="6">
        <div class="dis-center">
          <span class="text-fs-14">商户名称：</span>
          <select-page
            ref="searchRpiSelect"
            label="rpiName"
            value="rpiNo"
            :select.sync="countSearch.rpiNo"
            :url="website.searchLink.merchantUrl"
            placeholder-text="商户"
            filter-key="searchParam"
            width-fill
          ></select-page>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="dis-center">
          <span class="text-fs-14">通道简称：</span>
          <select-dict
            ref="aisleKind"
            :select.sync="countSearch.aisleKind"
            code="rbp_aisle_kind"
            placeholder-text="分账类型"
            width-fill
          ></select-dict>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="dis-center">
          <span class="text-fs-14">通道名称：</span>
          <select-page
            ref="searchAisSelect"
            label="aisleName"
            value="aisleCode"
            :select.sync="countSearch.aisleCode"
            :url="'aisle/rbp_pay_aisle/page'"
            placeholder-text="通道"
            filter-key="searchParam"
            width-fill
          ></select-page>
        </div>
      </el-col>
    </el-row>
    <div class="dis-center haruyuki-jc-c">
      <el-button
        type="primary"
        icon="el-icon-search"
        size="small"
        @click="handleSearch"
        >搜索</el-button
      >
      <el-button icon="el-icon-delete" size="small" @click="handleReset"
        >重置</el-button
      >
    </div>
    <div class="countcard">
      <div class="countcard-box countcard-bg-blue">
        <div class="countcard-box-title">账户资产</div>
        <div class="countcard-box-content">
          <div class="countcard-box-item">
            <div class="countcard-box-item-title color-white">账户总额(元)</div>
            <div class="countcard-box-item-number color-blue">
              {{ formatAmount(countData.accountTotalAmount) }}
            </div>
          </div>
          <!-- <div class="countcard-box-item">
            <div class="countcard-box-item-title color-white">可提现金额(元)</div>
            <div class="countcard-box-item-number color-blue">
              {{ formatAmount(countData.accountWithdrawBalance) }}
            </div>
          </div> -->
        </div>
        <!-- <div class="countcard-box-btn">
            <el-button round size="small" @click="handleWithdraw">提现</el-button>
        </div> -->
      </div>
      <div class="countcard-box">
        <div class="countcard-box-title">一般消费类账户</div>
        <div class="countcard-box-content">
          <div class="countcard-box-item">
            <div class="countcard-box-item-title">账户余额(元)</div>
            <div class="countcard-box-item-number">
              {{ formatAmount(countData.accountConsumeAmount) }}
            </div>
          </div>
        </div>
      </div>
      <div class="countcard-box">
        <div class="countcard-box-title">待结算账户</div>
        <div class="countcard-box-content">
          <div class="countcard-box-item">
            <div class="countcard-box-item-title">账户余额(元)</div>
            <div class="countcard-box-item-number">
              {{ formatAmount(countData.accountPendingSettlementAmount) }}
            </div>
          </div>
        </div>
      </div>
      <div class="countcard-box">
        <div class="countcard-box-title">待清算账户</div>
        <div class="countcard-box-content">
          <div class="countcard-box-item">
            <div class="countcard-box-item-title">账户余额(元)</div>
            <div class="countcard-box-item-number">
              {{ formatAmount(countData.accountSettledUnpaidAmount) }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- <avue-crud
      :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @sort-change="sortChange"
    >
      <template slot="menuLeft">
        
      </template>
      <template slot="menuRight">
        <el-button type="primary" size="small" @click="handleWithdraw">提现</el-button>
      </template>
    </avue-crud> -->
  </basic-container>
</template>

<script>
import { getStatistics } from "@/api/rb-oem/separateFunds/separate_funds";
import { mapGetters } from "vuex";
import selectPage from "@/components/select-page/select-page";
import selectDict from "@/components/select-dict/select-dict";

export default {
  name: "SeparateFunds",
  components: {
    selectPage,
    selectDict,
  },
  data() {
    return {
      form: {},
      query: {},
      search: {},
      countSearch: {
        rpiNo: '',
        aisleKind: '',
        aisleCode: '',
      },
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: "calc(50vh - 50px)",
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        viewBtn: false,
        editBtn: false,
        addBtn: false,
        delBtn: false,
        searchMenuSpan: 24,
        columnBtn: false,
        labelWidth: 170,
        searchLabelWidth: 110,
        menu: false,
        emptyBtnText: "重置",
        column: [
          {
            label: "分账项目",
            prop: "projectCode",
            type: "input",
            slot: true,
          },
          {
            label: "商户",
            prop: "rpiNo",
            type: "select",
            slot: true,
          },
          {
            label: "通道简称",
            prop: "aisleKind",
            type: "select",
            search: true,
            dicUrl: "/api/blade-system/dict/dictionary?code=rbp_aisle_kind",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            multiple: false,
            dataType: "string",
            showColumn: false,
          },
          {
            label: "通道名称",
            prop: "aisleCode",
            type: "select",
            slot: true,
          },
          //   {
          //     label: "账户类型",
          //     prop: "accountType",
          //     type: "select",
          //     dicUrl: "/api/blade-system/dict/dictionary?code=account_type",
          //     props: {
          //       label: "dictValue",
          //       value: "dictKey",
          //     },
          //     search: true,
          //     searchOrder: 2,
          //     overHidden: true,
          //     minWidth: 120
          //   },
        ],
      },
      data: [],
      countData: {},
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        viewBtn: this.vaildData(this.permission.separate_funds_view, false),
        exportBtn: this.vaildData(this.permission.separate_funds_export, false),
      };
    },
  },
  methods: {
    formatAmount(amount) {
      if (amount === undefined || amount === null || amount === "") {
        return "0.00";
      }
      return parseFloat(amount).toFixed(2);
    },
    beforeOpen(done, type) {
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page, this.query);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page, this.query);
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      //   getList(
      //     page.currentPage,
      //     page.pageSize,
      //     Object.assign(params, this.query)
      //   ).then((res) => {
      //     const data = res.data.data;
      //     this.page.total = data.total;
      //     this.data = data.records;
      //     this.loading = false;
      //   });
    },
    handleSearch() {
        if (!this.countSearch.rpiNo) {
          return this.$message.warning("请选择商户");
        }
        if (!this.countSearch.aisleKind) {
          return this.$message.warning("请选择通道简称");
        }
        if (!this.countSearch.aisleCode) {
          return this.$message.warning("请选择通道名称");
        }
        this.searchStatistics();
    },
    handleReset() {
      this.countSearch = {};
      this.searchStatistics();
    },
    searchStatistics(params = {}) {
      getStatistics(Object.assign(params, this.countSearch)).then((res) => {
        this.countData = res.data.data;
      });
    },
    handleWithdraw() {
      // 处理提现逻辑
      this.$message.info("提现功能开发中...");
    },
    sortChange(val) {
      if (val.order == "ascending") {
        this.query.ascs = val.prop;
        this.query.descs = "";
      } else {
        this.query.descs = val.prop;
        this.query.ascs = "";
      }
      this.refreshChange();
    },
  },
};
</script>

<style lang="scss" scoped>
.countcard {
  display: grid;
  grid-template-columns: repeat(4, 23%);
  gap: 16px;
  padding-top: 10px;
  padding-bottom: 20px;
  margin-top: 30px;

  .countcard-box {
    position: relative;
    padding: 15px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 10px 0px rgba(83, 136, 233, 0.15);

    .countcard-box-title {
      text-align: center;
      font-weight: bold;
      border-bottom: 1px solid rgba(214, 215, 217, 0.2);
      padding-bottom: 12px;
      font-size: 14px;
      color: #303133;
    }

    .countcard-box-content {
      padding-top: 15px;
      display: flex;
      align-items: center;
      justify-content: space-around;

      .countcard-box-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;

        .countcard-box-item-title {
          font-size: 13px;
          color: #666666;
          margin-bottom: 8px;
        }

        .countcard-box-item-number {
          font-size: 16px;
          font-weight: bold;
          color: #409eff;
        }
      }
    }

    .countcard-box-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        display: flex;
    }
  }
  .countcard-bg-blue {
    background: linear-gradient(30deg, #a3c9ff 0%, #66a6ff 100%);
  }
}

::v-deep .avue-crud__menu {
  display: block;
}

::v-deep .avue-crud__right {
  display: flex;
  justify-content: flex-end !important;
}

.dis-center {
  display: flex;
  align-items: center;
}

.haruyuki-jc-c {
  justify-content: center;
  margin-top: 20px;
}

.text-fs-14 {
  font-size: 14px;
  width: 100px;
  margin-left: 30px;
  margin-right: 6px;
}

.color-white {
  color: #ffffff !important;
}

.color-blue {
    color: #2c6eb2 !important;
}
</style>